import Mock from 'mockjs'

// TOKEN
const USERTOKEN = 'sdfdf231fds'
const ADMINTOKEN = 'isdfnvx123s'
// TOKEN列表
const tokens = {
  admin: ADMINTOKEN,
  user: USERTOKEN
}
/* 下面所说的权限列表其实就是路由列表 */
// 所有的权限列表

// 管理员的权限列表
const adminRoutes = [
  {
    path: '/mimi',
    redirect: '/mimi/list',
    component: 'Main',  // 修改了此处，就可以加载出头部和左侧菜单栏了
    // 当 设置 true 的时候该路由不会在侧边栏出现
    meta: { title: 'Mimi', hidden: false, icon: 'Mimi', roles: ['admin'] },
    children: [
      {
        path: 'list',
        name: 'AssetsUdiskList',
        component: 'AssetsUdiskList',
        meta: { title: 'Assets_udiskList', hidden: false, roles: ['admin'] }
      },
      {
        path: 'assets/terminalList',
        name: 'AssetsTerminalList',
        component: 'AssetsTerminalList',
        meta: { title: 'Assets_terminalList', hidden: false, roles: ['admin'] }
      },
      {
        path: 'assets/printerList',
        name: 'AssetsPrinterList',
        component: 'AssetsPrinterList',
        meta: { title: 'Assets_printerList', hidden: false, roles: ['admin'] }
      },
      {
        path: 'assets/burnerList',
        name: 'AssetsBurnerList',
        component: 'AssetsBurnerList',
        meta: { title: 'Assets_burnerList', hidden: false, roles: ['admin'] }
      },
      {
        path: 'person/personList',
        name: 'PersonPersonList',
        component: 'PersonPersonList',
        meta: { title: 'Person_personList', hidden: false, roles: ['admin'] }
      },
    ]
  },
  {
    path: '/alarm',
    component: 'Main',  // 修改了此处，就可以加载出头部和左侧菜单栏了
    redirect: '/alarm/list',
    meta: { title: 'UdiskAlarm', hidden: false, icon: 'udiskAlarm', roles: ['admin'] },
    children: [
      {
        path: 'list',
        name: 'UdiskAlarm',
        component: 'UdiskAlarm',
        meta: { title: 'Udisk_alarm', hidden: false, roles: ['admin'] }
      },
      {
        path: 'userAlarm/terminalAlarm',
        name: 'TerminalAlarm',
        component: 'TerminalAlarm',
        meta: { title: 'Terminal_alarm', hidden: false, roles: ['admin'] }
      },
    ]
  },
]
// 用户的权限列表
const userRoutes = [
  {
    path: '/mimi',
    redirect: '/mimi/list',
    // component: () => import('../views/Lay'),
    component: 'Main',  // 修改了此处，就可以加载出头部和左侧菜单栏了
    // 当 设置 true 的时候该路由不会在侧边栏出现
    meta: { title: 'Mimi', hidden: false, icon: 'Mimi', roles: ['user'] },
    children: [
      {
        path: 'list',
        name: 'AssetsUdiskList',
        component: 'AssetsUdiskList',
        meta: { title: 'Assets_udiskList', hidden: false, roles: ['user'] }
      },
      {
        path: 'assets/terminalList',
        name: 'AssetsTerminalList',
        component: 'AssetsTerminalList',
        meta: { title: 'Assets_terminalList', hidden: false, roles: ['user'] }
      },
      {
        path: 'assets/printerList',
        name: 'AssetsPrinterList',
        component: 'AssetsPrinterList',
        meta: { title: 'Assets_printerList', hidden: false, roles: ['user'] }
      },
      {
        path: 'assets/burnerList',
        name: 'AssetsBurnerList',
        component: 'AssetsBurnerList',
        meta: { title: 'Assets_burnerList', hidden: false, roles: ['user'] }
      },
    ]
  },
]
// 用户信息
const users = {
  [ADMINTOKEN]: {
    roles: ['admin'],
    uroutes: adminRoutes,
    introduction: 'I am a super administrator',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Admin'
  },
  [USERTOKEN]: {
    roles: ['user'],
    uroutes: userRoutes,
    introduction: 'I am an editor',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Editor'
  }
}

Mock.mock('/user/login', 'get', {
  code: 200,
  data: {
    'token': tokens.user,
    'user': users[USERTOKEN]
  }
})
Mock.mock('/admin/login', 'get', {
  code: 200,
  data: {
    'token': tokens.admin,
    'user': users[ADMINTOKEN]
  }
})

// 登录
Mock.mock('/login', 'post', function(option){
  // 请求相关的参数
  // console.log(option)
  if (option.body == 'user') {
    return Mock.mock({
      code: 200,
      data: {
        'token': tokens.user,
        'name': users[USERTOKEN].name
      }
    })
  } else {
    return Mock.mock({
      code: 200,
      data: {
        'token': tokens.admin,
        'name': users[ADMINTOKEN].name
      }
    })
  }
})

// 获取用户信息
Mock.mock('/getUserInfo', 'post', function(option){
  // 请求相关的参数
  // console.log(option)
  if (option.body == 'Editor') {
    return Mock.mock({
      code: 200,
      data: {
        'user': users[USERTOKEN]
      }
    })
  } else {
    return Mock.mock({
      code: 200,
      data: {
        'user': users[ADMINTOKEN]
      }
    })
  }
})

// export default mockUsers
